package com.youhome.service.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.youhome.service.mapper.ProductMapper;
import com.youhome.service.model.Product;
import com.youhome.service.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by chen365 on 2017/9/11.
 */
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public Product selectByPrimaryKey(Long id) throws Exception {
        return productMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<Product> selectAll(Product record, int pageNumber, int pageSize) throws Exception {
        if (StringUtils.isEmpty(pageNumber) || pageNumber < 1)
            pageNumber = 1;
        if (StringUtils.isEmpty(pageSize) || pageSize < 1)
            pageSize = 10;
        PageHelper.startPage(pageNumber, pageSize);
        List<Product> list = productMapper.selectAll(record);
        return new PageInfo<>(list);
    }

}
